<template>
  <div class="sxs">
    <div class="box">
      <h2>后台管理系统 <span class="zhi">v3.0</span></h2>
      <el-form
        :label-position="labelPosition"
        :model="formLabelAlign"
        class="inp"
      >
        <el-form-item label="">
          <el-input
            v-model="formLabelAlign.mobile"
            placeholder="账号登录"
            prefix-icon="el-icon-user-solid"
          ></el-input>
        </el-form-item>
        <el-form-item label="">
          <el-input
            v-model="formLabelAlign.pwd"
            placeholder="密码登录"
            prefix-icon="el-icon-lock"
            type="password"
            show-password
          ></el-input>
        </el-form-item>
        <el-form-item label="">
          <el-input
            v-model="formLabelAlign.imgcode"
            placeholder="验证码"
            prefix-icon="el-icon-picture"
          >
          </el-input>
          <img width="80" height="36px" :src="codeSrc" alt="" />
        </el-form-item>
        <el-checkbox v-model="checked" class="xuan">记住登录状态</el-checkbox>
        <el-button type="primary" class="an" @click="zhang">登录</el-button>
      </el-form>
    </div>
  </div>
</template>
<script>
import { bannerzanhao } from "@/api";
export default {
  data() {
    return {
      labelPosition: "right",
      formLabelAlign: {},
      // name: "",
      // region: "",
      // type: "",
      codeSrc: "",
      k: "",
      checked: false,
    };
  },
  methods: {
    getTmage() {
      this.k = Math.random();
      this.codeSrc = "https://user.api.it120.cc/code?k=" + this.k;
    },
    zhang() {
      this.formLabelAlign.k = this.k;
      // console.log(this.formLabelAlign);
      bannerzanhao(this.formLabelAlign).then((res) => {
        // console.log(res);
        if (res.code === 0) {
          // 登录成功之后需 把信息储存到localStorage
          localStorage.setItem("userInfo", JSON.stringify(res.data));
          this.$router.push("/index");
        } else {
          this.getTmage();
        }
      });
    },
  },
  mounted() {
    this.getTmage();
  },
};
</script>
<style scoped>
/* 大框 */
.box {
  width: 520px;
  /* height: 620px; */
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: #2d3a4b;
}
/* 后台字体 */
h2 {
  text-align: center;
  color: #eee;
  margin-bottom: 30px;
  font-weight: 800;
}
/* 后台字体 v3.0 */
.zhi {
  font-size: 14px;
  color: rgb(170, 170, 170);
}
/* 登录选择框 */
.xuan {
  margin-bottom: 22px;
  color: rgb(221, 221, 221);
}
/* 登录按钮 */
.an {
  width: 100%;
}
</style>

<style lang="less">
.sxs {
  .el-input__inner {
    background-color: #2d3a4b;
  }
  .el-form-item__content {
    position: relative;
    img {
      position: absolute;
      right: 10px;
      top: 50%;
      transform: translateY(-50%);
    }
  }
}
</style>>

